import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:live_music/pages/home/index/page_view/discover_index.dart';
import 'package:live_music/pages/home/index/page_view/follow_index.dart';
import 'package:live_music/pages/search/index.dart';
import 'package:live_music/utils/colors.dart';

class PageViewIndex extends StatefulWidget {
  PageViewIndex({Key key}) : super(key: key);
  @override
  _PageViewIndexState createState() => _PageViewIndexState();
}

class _PageViewIndexState extends State<PageViewIndex>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;
  final List<Widget> _tabsContent = [FollowIndex(), DiscoverIndex()];
  final List<Widget> _tabs = [Text('关注'), Text('发现')];
  @override
  void initState() {
    super.initState();
    _tabController = TabController(
      initialIndex: 1,
      length: _tabs.length,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      backgroundColor: ColorRes.themeBg,
      appBar: AppBar(
          automaticallyImplyLeading: false,
          centerTitle: true,
          title: _getTopBarLayout(),
          actions: <Widget>[
            IconButton(
              onPressed: () {
                Get.to(SearchIndexPage());
              },
              icon: Icon(
                Icons.search_rounded,
                color: Colors.redAccent,
              ),
            )
          ]),
      body: ExtendedTabBarView(
        controller: _tabController,
        children: _tabsContent,
      ),
    );
  }

  _getTopBarLayout() {
    return Container(
        width: 0.35 * MediaQuery.of(context).size.width,
        child: ExtendedTabBar(
          indicatorSize: TabBarIndicatorSize.label,
          controller: _tabController,
          indicatorColor: ColorRes.tabLine,
          indicatorWeight: 2,
          unselectedLabelStyle:
              TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
          labelStyle:
              TextStyle(fontSize: 15, fontWeight: FontWeight.w600), //标签文字大小颜色
          tabs: _tabs,
        ));
  }

  @override
  bool get wantKeepAlive => true;
}
